// pages/index/index.js
const app = getApp();
var windowHeight = app.globalData.windowHeight
var windowWidth = app.globalData.windowWidth
import {
  ajax,
  src,
  util
} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 新手教程
    windowHeight: windowHeight,
    windowWidth: windowWidth,
    po_data1: '',
    po_data2: '',
    po_data3: '',

    showxsjc: false,
    // 授权登录
    islogin: false,
    // 展示图片和文件
    tupianlist:'',
    wenjianlist:'',
    // userId:2,
    parentId:0,
    timeSlot:0,
    orderType: 2,  // 2 最近 3，常用
    // 全选弹框
    showqxtc:false,
    quanxuan:0,
    xznum:0,
    arrid:[],
    showpldeltc:false,
    // 长按图片
    start:'',
    end:'',
    // 三个点
    showsantc:false,
    idzhi:'',
    namezhi:'',
    ischangyong:'',
    isxingbiao:'',

    fileFormat:"",
    filename: "",
    // 重命名和删除
    showupnametc:false,
    showdeltc:false,
    // 加号弹框
    showjiahaotc:false,


    headImg: [],
    // 新建文件夹
    shownewwjtc:false,
    newFolderName:'',

    // showxsjc:true,

    list:'',
    //不可预览弹窗
    shownotyulantc:false,

    currentuuid:"",
    isAudit:false
  },

  focus:function(){
    currentTarget.select();
  },
  



  // 常用  最近  切换
  numck:function(e){
    var num = e.target.dataset.num
    this.setData({
      orderType: num,
      tupianlist:[],
      wenjianlist:[]
    })
    this.gettupian()
    this.getwenjian()
  },
  // 跳转搜索页面
  search:function(){
    wx.navigateTo({
      url: '/pages/search/search?thismuluid=' + 0,
    })
  },
  // 跳转图片页
  totupage: function () {
    if (this.data.orderType == 3){
      wx.navigateTo({
        url: '/pages/tupage/tupage?thismuluid= -2'
      })
    }else{
      wx.navigateTo({
        url: '/pages/tupage/tupage?thismuluid= -1'
      })
    }
  },


  settime(id) {
    ajax('/applet/updateTime', {
      data: {
        id: id
      },
      header: {
        "Accept": "application/json" // 默认值
      },
      method: "post",
    }, res => {
      console.log(res.data.list)
      if (res.msg == "SUCCESS") {

      }
    })
  },
  // 跳转文件页
  totowenjian: function (e) {
    console.log(e)
    var id = e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    var muluname = e.currentTarget.dataset.muluname
    var src = e.currentTarget.dataset.src
    var preview = e.currentTarget.dataset.preview

    var uuid = e.currentTarget.dataset.uuid

    // console.log(src)
    // var srclist = src.split("?");

    // console.log(srclist)
    src = encodeURIComponent(src)
    


    console.log(src,"4444444444444444")

    if (type == 0) {
      wx.navigateTo({
        url: '/pages/towenjian/towenjian?thismuluid=' + id + '&muluname=' + muluname,
      })
    } else {
      if (preview == 1) {
        // wx.navigateTo({
        //   url: '/pages/details/details?src='+ src
        // })


        var huancun = wx.getStorageSync('huancun')

        if (huancun == '') {
          huancun = []
          wx.downloadFile({
            // 示例 url，并非真实存在
            url: decodeURIComponent(src),
            success: function (res) {
              console.log("aaa:" + "666a");
              const filePath = res.tempFilePath


              var item = {
                id: id,
                tempFilePath: filePath
              }
              huancun.push(item)

              wx.setStorageSync('huancun', huancun)

              wx.openDocument({
                filePath: filePath,
                success: function (res) {
                  console.log('打开文档成功')
                }
              })
            }
          })
        } else {

          var flage = -1
          for (var i = 0; i < huancun.length; i++) {
            if (huancun[i].id == id) {
              flage = i
            }
          }

          if (flage != -1) {
            wx.openDocument({
              filePath: huancun[flage].tempFilePath,
              success: function (res) {
                console.log('打开文档成功')
              }
            })
          } else {
            wx.downloadFile({
              // 示例 url，并非真实存在
              url: decodeURIComponent(src),
              success: function (res) {
                console.log("aaa:" + "666a");
                const filePath = res.tempFilePath


                var item = {
                  id: id,
                  tempFilePath: filePath
                }
                huancun.push(item)

                wx.setStorageSync('huancun', huancun)

                wx.openDocument({
                  filePath: filePath,
                  success: function (res) {
                    console.log('打开文档成功')
                  }
                })
              }
            })
          }
        }

        this.settime(id)
      } else {
        this.setData({
          currentuuid: uuid
        })

        this.setData({
          shownotyulantc:true
        })
      }
    }

  },


  copy: function (e) {
   
    var that = this;
    wx.setClipboardData({
      data: that.data.currentuuid,
      success: function (res) {
        that.ylquxiao()
      }
    });
  },
  // 授权登录
  bindGetUserInfo(e) {
    console.log('授权登录')
  },
  // 展示图片
  gettupian(){
    ajax('/applet/viewPicture', {
      data: {
        // userId: this.data.userId,
        parentId: this.data.parentId,
        timeSlot: this.data.timeSlot,
        orderType: this.data.orderType,
        page: 1,
        size: 100,
      },
      header: {
        "Accept": "application/json"
      },
      method: "post",
    }, res => {
      console.log('获取图片成功')
      for (var a in res.data.list){
        res.data.list[a].choose = 0     // 0未选中  1选中
      }
      // var tupianlist = res.data.list

      console.log('获取文件成功')
      res.data.list.forEach((valve, index) => {

        if (valve.fileType == 0) {

          valve.fileFormat = valve.fileName
          valve.firstname = valve.fileName
        } else {

          let fileName = valve.fileName.lastIndexOf(".");//取到文件名开始到最后一个点的长度
          let fileNameLength = valve.fileName.length;//取到文件名长度
          let fileFormat = valve.fileName.substring(fileName + 1, fileNameLength);//截
          let firstname = valve.fileName.substring(0, fileName);//截
          valve.fileFormat = fileFormat
          valve.firstname = firstname
        }
      })
      for (var a in res.data.list) {
        res.data.list[a].choose = 0     // 0未选中  1选中
      }
      var tupianlist = res.data.list

      this.setData({
        tupianlist: tupianlist
      })
    })
  },
  // 展示文件
  getwenjian() {
    ajax('/applet/viewFile', {
      data: {
        // userId: this.data.userId,
        parentId: this.data.parentId,
        timeSlot: this.data.timeSlot,
        orderType: this.data.orderType,
        page: 1,
        size: 100,
      },
      header: {
        "Accept": "application/json"
      },
      method: "post",
    }, res => {
      console.log('获取文件成功')
      res.data.list.forEach((valve, index) => {

        if (valve.fileType == 0) {

          valve.fileFormat = valve.fileName
          valve.firstname = valve.fileName
        } else {

          let fileName = valve.fileName.lastIndexOf(".");//取到文件名开始到最后一个点的长度
          let fileNameLength = valve.fileName.length;//取到文件名长度
          let fileFormat = valve.fileName.substring(fileName + 1, fileNameLength);//截
          let firstname = valve.fileName.substring(0, fileName);//截
          valve.fileFormat = fileFormat
          valve.firstname = firstname
        }
      })
      for (var a in res.data.list) {
        res.data.list[a].choose = 0     // 0未选中  1选中
      }
      var wenjianlist = res.data.list
      this.setData({
        wenjianlist: wenjianlist
      })
    })
  },
  // 展示大加号弹框
  dajiahan(){
    this.setData({
      showjiahaotc:true
    })
  },
  // 取消大加号弹框
  quxiaodajiahao(){
    this.setData({
      showjiahaotc: false
    })
  },
  // 选图片
  uploadimages: function () {
    this.setData({
      headImg: [],
      showjiahaotc: false
    })

    var that = this
    wx.showActionSheet({
      itemList: ['从相册选取', '拍照'],
      success(res) {
        console.log(res.tapIndex)
        var index = res.tapIndex;

        var headImg = that.data.headImg;

        if (index == 0) {
          wx.chooseImage({
            count: 9,
            sizeType: ['original', 'compressed'],
            sourceType: ['album'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片
              const tempFilePaths = res.tempFilePaths;
              console.log(tempFilePaths)


              for (let i = 0; i < tempFilePaths.length; i++) {
                var obj = {}
                obj.path = tempFilePaths[i]
                headImg.push(obj)
              }
              that.setData({
                headImg: headImg
              });

              wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=0' + '&thismuluid=' + that.data.parentId, })
            }
          })
        } else if (index == 1) {
          wx.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'],
            sourceType: ['camera'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片

              var headImg = that.data.headImg;

              const tempFilePaths = res.tempFilePaths;

              var obj = {}
              obj.path = tempFilePaths[0]
              headImg.push(obj)
              that.setData({
                headImg: headImg
              });
              wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=0' + '&thismuluid=' + that.data.parentId, })
            }
          })
        }

      },
      fail(res) {
        console.log(res.errMsg)
      }
    })

  },
  // 选视频
  uploadvideo: function () {
    this.setData({
      headImg: [],
      showjiahaotc: false
    })

    var that = this
    wx.showActionSheet({
      itemList: ['从相册选取', '拍照'],
      success(res) {
        console.log(res.tapIndex)
        var index = res.tapIndex;

        var headImg = that.data.headImg;
        if (index == 0) {

          wx.chooseVideo({
            // count: num,
            maxDuration: 15,
            camera: 'back',

            sourceType: ['album'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片
              const tempFilePaths = res.tempFilePath;
              var obj = {}

              obj.path = tempFilePaths
              headImg.push(obj)
              that.setData({
                headImg: headImg
              });

              wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=1' + '&thismuluid=' + that.data.parentId, })
            }
          })
        } else if (index == 1) {
          wx.chooseVideo({

            maxDuration: 15,
            camera: 'back',

            sourceType: ['camera'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片

              var headImg = that.data.headImg;

              const tempFilePaths = res.tempFilePath;

              var obj = {}
              obj.style = 2
              obj.path = tempFilePaths
              headImg.push(obj)

              that.setData({
                headImg: headImg
              });

              wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=1' + '&thismuluid=' + that.data.parentId, })
            }
          })
        }

      },
      fail(res) {
        console.log(res.errMsg)
      }
    })

  },
  // 选微信文件
  uploadwxwenjian: function () {
    this.setData({
      headImg: [],
      showjiahaotc: false
    })

    var that = this
    wx.chooseMessageFile({
      count: 10,
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        var headImg = that.data.headImg;
        const tempFilePaths = res.tempFiles;
        console.log(tempFilePaths)


        for (let i = 0; i < tempFilePaths.length; i++) {
          var obj
          obj = tempFilePaths[i]
          headImg.push(obj)
        }
        that.setData({
          headImg: headImg
        });

        wx.navigateTo({ url: '/pages/shangchuan/shangchuan?headImg=' + JSON.stringify(headImg) + '&type=2' + '&thismuluid=' + that.data.parentId, })
      }
    })
  },
  // 展示新建文件夹
  addxinwenjianjia: function () {
    this.setData({
      showjiahaotc: false,
      shownewwjtc:true
    })
  },
  // 取消新建文件夹
  quxiaoxinjianwenjianjia:function(){
    this.setData({
      shownewwjtc: false
    })
  },
  // 新建文件夹名字
  setNewFolderName: function (e) {
    // console.log(e.detail.value)
    this.setData({
      newFolderName: e.detail.value
    })
  },
  // 新建文件夹确认ajax
  surecreateFolder:function(){
    if (this.data.newFolderName==''){
      wx.showToast({
        title: '文件夹名称不能为空',
        icon: 'none',
        duration: 2000
      })
      return
    }
    ajax('/applet/appletCreateFolder', {
      data: {
        // 为必填 
        // userId: this.data.userId,
        // 为必填 如果是根目录请传0
        parentId: this.data.parentId,
        //  为必填 填写文件夹名即可
        fileName: this.data.newFolderName
      },
      header: {
        "Accept": "application/json" // 默认值
      },
      method: "post",
    }, res => {
      // console.log(res)
      if (res.msg == "SUCCESS") {
        this.setData({
          shownewwjtc:false
        })
        wx.showToast({
          title: '新建成功',
          icon: 'success',
          duration: 2000
        })
      }

      this.getwenjian()
    })
  },
  // 全选框显示
  showquanxuan(){
    this.setData({
      showqxtc:true
    })
  },
  // 全选框隐藏
  quanxuanquxiao(){
    this.setData({
      showqxtc: false,
    })
  },
  // 全部选中
  quanbuxuanzhong(){
    var arr = this.data.tupianlist
    var arr1 = this.data.wenjianlist
    for (var index in arr){
      var xuanzhong = "tupianlist[" + index + "].choose";
      this.setData({
        [xuanzhong]: 1
      })
    }
    for (var index in arr1) {
      var xuanzhong = "wenjianlist[" + index + "].choose";
      this.setData({
        [xuanzhong]: 1
      })
    }
    this.setData({
      quanxuan:1
    })
    this.xuanzhongnum()
  },
  // 取消全部选中
  quxiaoxuanzhong(){
    var arr = this.data.tupianlist
    var arr1 = this.data.wenjianlist
    for (var index in arr) {
      var xuanzhong = "tupianlist[" + index + "].choose";
      this.setData({
        [xuanzhong]: 0
      })
    }
    for (var index in arr1) {
      var xuanzhong = "wenjianlist[" + index + "].choose";
      this.setData({
        [xuanzhong]: 0
      })
    }
    this.setData({
      quanxuan: 0
    })
    this.xuanzhongnum()
  },
  // 全选框图片点击未选
  weixuan(e){
    var index = e.target.dataset.index
    var xuanzhong = "tupianlist[" + index + "].choose";
    this.setData({
      [xuanzhong]: 1
    })
    this.xuanzhongnum()
  },
  // 全选框图片点击已选
  yixuan(e) {
    var index = e.target.dataset.index
    var xuanzhong = "tupianlist[" + index + "].choose";
    this.setData({
      [xuanzhong]: 0
    })
    this.xuanzhongnum()
  },
  // 全选框文件点击未选
  wenweixuan(e) {
    var index = e.target.dataset.index
    var xuanzhong = "wenjianlist[" + index + "].choose";
    this.setData({
      [xuanzhong]: 1
    })
    this.xuanzhongnum()
  },
  // 全选框文件点击已选
  wenyixuan(e) {
    var index = e.target.dataset.index
    var xuanzhong = "wenjianlist[" + index + "].choose";
    this.setData({
      [xuanzhong]: 0
    })
    this.xuanzhongnum()
  },
  // 全选循环查看多少个选中
  xuanzhongnum(){
    var arr = this.data.tupianlist
    var arr1 = this.data.wenjianlist
    var arrid = []
    var tunum = 0
    var wennum = 0
    for (var index in arr){
      if (arr[index].choose == 1){
        console.log(tunum,'tunum')
        tunum += 1
        var id = arr[index].id
        arrid.push(id)
      } 
    }
    for (var index in arr1) {
      if (arr1[index].choose == 1) {
        console.log(wennum, 'wennum')
        wennum += 1
        var id = arr1[index].id
        arrid.push(id)
      }
    }
    this.setData({
      xznum: tunum + wennum,
      arrid: arrid
    })
  },
  // 全选显示批量删除框
  piliangshanchu(){
    if (this.data.arrid.length == 0){
      wx.showToast({
        title: '请选择文件',
        icon: 'none',
        duration: 2000
      })
      return
    }else{
      this.setData({
        showpldeltc: true
      })
    }
    
  },

  piliangfenxiang(){
    console.log(this.data.arrid,'this.data.arrid')
    if (this.data.arrid.length == 0){
      wx.showToast({
        title: '请选择文件',
        icon: 'none',
        duration: 2000
      })
      return
      
    }else{
      
      wx.navigateTo({
        url: '/pages/fenxiang/fenxiang?idlist=' + this.data.arrid,
      })
      this.setData({
        arrid: [],
        quanxuan: 0,
        xznum: 0,
      })
    }

    
  },


  // 全选取消批量删除矿
  plscquxiao(){
    this.setData({
      showpldeltc:false
    })
  },
  // 全选批量删除ajax
  plscqueren(){
    ajax('/applet/appletDelete', {
      data: {
        id: this.data.arrid,
      },
      header: {
        "Accept": "application/json"
      },
      method: "post",
    }, res => {
      console.log('批量删除成功')
      this.setData({
        showpldeltc: false,
        showqxtc: false
      })
      this.gettupian()
      this.getwenjian()
    })
  },
  // bindtouchstart：触屏开始时间
  // bindtouchend ：触屏结束时间
  // bindlongtap：绑定长按事件
  // catchtap：单击事件
  mytouchstart: function (e) {  //记录触屏开始时间
    this.setData({ start: e.timeStamp })
  },
  mytouchend: function (e) {  //记录触屏结束时间
    this.setData({ end: e.timeStamp })
  },
  deleteitem: function (e) {  //长按事件内容
    console.log('长按事件内容')
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    var ischangyong = e.currentTarget.dataset.ischangyong;
    var isxingbiao = e.currentTarget.dataset.isxingbiao

    var fileFormat = e.currentTarget.dataset.fileformat
    var filename = e.currentTarget.dataset.filename

    console.log(e)

    this.setData({
      idzhi: id,
      namezhi: name,
      ischangyong: ischangyong,
      isxingbiao: isxingbiao,
      showsantc: true,
      fileFormat: fileFormat,
      filename: filename
    })
  },
  onLinkDatail: function (e) {   //单击事件内容
    if (this.data.end - this.data.start < 350) {
      console.log('单击事件内容')
      console.log(e)
      var current = e.target.dataset.src;
      var index = e.currentTarget.dataset.ind;
      var imglist = []
      this.data.tupianlist.forEach((value, index) => {
        imglist.push(value.previewUrl)
      })
      var newlist = []
      for (var i = index; i < imglist.length; i++) {
        newlist.push(imglist[i])
      }
      for (var i = 0; i < index; i++) {
        newlist.push(imglist[i])
      }
      wx.previewImage({
        current: current, // 当前显示图片的http链接 
        urls: newlist // 需要预览的图片http链接列表 
      })
    }
  },
  // 三个点显示
  sanxianshi(e){
    var id = e.currentTarget.dataset.id;
    var name = e.currentTarget.dataset.name;
    var ischangyong = e.currentTarget.dataset.ischangyong;
    var isxingbiao = e.currentTarget.dataset.isxingbiao;

    var fileFormat = e.currentTarget.dataset.fileformat

    var filename = e.currentTarget.dataset.filename

    console.log(isxingbiao,'isxingbiao')
    this.setData({
      idzhi:id,
      namezhi:name,
      ischangyong: ischangyong,
      isxingbiao: isxingbiao,
      showsantc:true,
      fileFormat: fileFormat,
      filename: filename
    })
  },
  // 三个点隐藏
  sanquxiao() {
    this.setData({
      showsantc: false
    })
  },
  // 三个点设为常用
  swcy(){
    var isCommonly;
    if (this.data.ischangyong == 0){
      isCommonly = 1
    }else{
      isCommonly = 0
    }
    ajax('/applet/appletRename', {
      data: {
        id:this.data.idzhi,
        isCommonly: isCommonly        // 1为常用 0为非常用
      },
      header: {
        "Accept": "application/json"
      },
      method: "post",
    }, res => {
      console.log('设为常用成功')
      this.setData({
        showsantc: false
      })
      this.gettupian()
      this.getwenjian()
    })
  },
  // 三个点设为星标
  swxb() {
    var isxingbiao;
    if (this.data.isxingbiao == 0) {
      isxingbiao = 1
    } else {
      isxingbiao = 0
    }
    ajax('/applet/appletRename', {
      data: {
        id: this.data.idzhi,
        isFollow: isxingbiao        // 1为星标 0为非星标
      },
      header: {
        "Accept": "application/json"
      },
      method: "post",
    }, res => {
      console.log('设为星标成功')
      this.setData({
        showsantc: false
      })
      this.gettupian()
      this.getwenjian()
    })
  },
  // 重命名显示
  swcmm(){
    this.setData({
      showsantc: false,
      showupnametc:true
    })
  },
  // 重命名的值
  getnamezhi(e){
    this.setData({
      namezhi: e.detail.value
    })  
  },

  delnamezhi(){
    this.setData({
      namezhi: ''
    }) 
  },

  delnamezhi1() {
    this.setData({
      newFolderName: ''
    })
  },
  // 重命名隐藏
  cmmquxiao(){
    this.setData({
      showupnametc: false
    })
  },
  // 重命名确认ajax
  cmmqqueren(){
    if (this.data.namezhi==''){
      wx.showToast({
        title: '名称不能为空',
        icon: 'none',
        duration: 2000
      })
      return
    }

    if (this.data.filename == this.data.fileFormat ){
      var pinname = this.data.namezhi 
    }else{
      var pinname = this.data.namezhi + '.' + this.data.fileFormat   
    }

    ajax('/applet/appletRename', {
      data: {
        id: this.data.idzhi,
        fileName: pinname
      },
      header: {
        "Accept": "application/json"
      },
      method: "post",
    }, res => {
      console.log('重命名成功')
      this.setData({
        showupnametc: false
      })
      this.gettupian()
      this.getwenjian()
    })
  },
  // 单个分享
  swfx(){
      wx.navigateTo({
        url: '/pages/fenxiang/fenxiang?idlist=' + [this.data.idzhi],
      })
    
  },
  // 删除框显示
  swsc(){
    this.setData({
      showsantc: false,
      showdeltc: true
    })
  },
  // 删除框隐藏
  scquxiao() {
    this.setData({
      showdeltc: false
    })
  },

  // 预览框隐藏
  ylquxiao() {
    this.setData({
      shownotyulantc: false,
      currentuuid:''
    })
  },

  // 删除框确认ajax
  scqueren() {
    ajax('/applet/appletRename', {
      data: {
        id: this.data.idzhi,
        isDelete: 1         // 1为删除 0为不删除
      },
      header: {
        "Accept": "application/json"
      },
      method: "post",
    }, res => {
      console.log('删除成功')
      this.setData({
        showdeltc: false
      })
      this.gettupian()
      this.getwenjian()
    })
  },
  // 隐藏新手教程
  tgxsjc:function(){
    this.setData({
      isFirst:false,

    })
    wx.setStorageSync('isFirst',false)
  },

  clearArc: function (x, y, radius, stepClear,cxt) {
      var calcWidth = radius - stepClear;
      var calcHeight = Math.sqrt(radius * radius - calcWidth * calcWidth);

      var posX = x - calcWidth;
      var posY = y - calcHeight;

      var widthX = 2 * calcWidth;
      var heightY = 2 * calcHeight;

      if(stepClear <= radius) {
        cxt.clearRect(posX, posY, widthX, heightY);
        stepClear += 0.1;
        this.clearArc(x, y, radius, stepClear, cxt);
      }
  },

  clearArcFun:function(x, y, r, cxt) {
    var stepClear = 0.1;//这是定义精度 
    this.clearArc(x, y, r, stepClear,cxt);
  },
  xinshoujiaocheng:function(){
    // this.data.
    console.log('1111')
    this.ctx = wx.createCanvasContext('myCanvas')
    this.ctx.setFillStyle('rgba(0,0,0,0.5)')
    this.ctx.fillRect(0, 0, this.data.windowWidth, this.data.windowHeight)
    const aa = wx.createSelectorQuery()

    aa.select('#wenitem').boundingClientRect()
    aa.select('#wenitem .right1').boundingClientRect()
    aa.select('.dajiahao').boundingClientRect()
    var that = this
    aa.exec(function (res) {
      //res就是 该元素的信息 数组
      console.log(res);
      //取高度
      //抠出一个矩形区域
      that.ctx.clearRect(res[1].left - 10, res[0].top + 6, res[1].width + 20, 30);

      that.setData({
        po_data2: {
          'left': res[1].left - 120,
          'top': res[0].top - 80,
        }
      })
      //抠出一个矩形区域
      that.ctx.clearRect(10, res[0].top - 9, 200, 60);

      that.setData({
        po_data1: {
          'left': 10 + 100 - 75,
          'top': res[0].top + 100,
        }
      })
      //抠出一个圆形区域
      that.clearArcFun(res[2].left + res[2].width / 2, res[2].top + res[2].width / 2, res[2].width / 2 + 3, that.ctx)
      // that.clearArcFun(res[2].left + res[2].width / 2 , res[2].top + res[2].width / 2, res[2].width/2+5, that.ctx)
      that.setData({
        po_data3: {
          'left': res[2].left - 90,
          'top': res[2].top - 90,
        }
      })

      that.ctx.draw()

      that.setData({
        isFirst: wx.getStorageSync('isFirst'),
      })
    })

   


    // x, y)为要清除的圆的圆心，r为半径，cxt为context
    //   * 用clearRect方法清除canvas上不能用clip剪切的圆形
  },
  /**
   * 生命周期函数--监听页面加载
   */
  getVersionStatus:function(){
    var that=this
    ajax('/getVersionStatus', {
      
      header: {
        "Accept": "application/json"
      },
      method: "get",
    }, res => {
     console.log(res)
     if(res.msg=="SUCCESS"){
      console.log(res.data.isAudit);
      if(res.data.isAudit == false){
        wx.setStorageSync('isAudit', false)
          that.setData({
            isAudit:false
          })
        console.log(res.data.isAudit);
        if (wx.getStorageSync("sessionKey")){
      
        }else{
          wx.navigateTo({
            url: '/pages/login/login',
          })
        }
       
      }
      else{
        if (wx.getStorageSync("sessionKey")){
          if(wx.getStorageSync("isAudit")=='11111'){
            that.setData({
              isAudit:false
            })
          }  
        }else{
          console.log(wx.getStorageSync("isAudit"))
         if(wx.getStorageSync("isAudit")=='11111'){
            console.log('没重设')
         }else{
          wx.setStorageSync('isAudit', true)
          that.setData({
            isAudit:true
          })
         }
          wx.setStorageSync('token', res.data.token)
          
          this.gettupian()
          this.getwenjian()
        }
       
      }
     }
    })
  },

  tologin:function(){
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },

  onLoad: function (options) {
    this.getVersionStatus()
    
    

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if(wx.getStorageSync("isAudit")=='11111'){
      this.setData({
        isAudit:false
      })
    }else{
      this.setData({
        isAudit:true
      })
    }
    this.gettupian()
    this.getwenjian()
    var that =this

    this.setData({
      xznum: 0,
      quanxuan:0,
    })

    if (wx.getStorageSync('isFirst')) {
      var that=this
      setTimeout(function () {
        that.xinshoujiaocheng()
      }, 1500)
    }
   
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.setData({
      showqxtc: false,
      showpldeltc: false,

      showupnametc: false,
      showdeltc: false,
      // 加号弹框
      showjiahaotc: false,
      showsantc: false,
      // 新建文件夹
      shownewwjtc: false,
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    wx.stopPullDownRefresh()
  }
})